import requests

from api_input_tools import get_api_input


def API(api_name, args):
    domain = "comm.chatglm.cn"
    url = f"https://{domain}/law_api/s1_b/{api_name}"
    headers = {
        'Content-Type': 'application/json',
        'Authorization': 'Bearer BD85D26446A832F013674F7F2F8ACF8395146866479D2D59'
    }
    rsp = requests.post(url, json=args, headers=headers)
    return rsp.json()


if __name__ == "__main__":
    '''
    value = "保定市天威西路2222号"
    api_name = "get_address_info"
    api_input = get_api_input(api_name, value)

    response = API(api_name, api_input)
    print(response)
    '''

    '''
    value = "上海东方华银律师事务所"
    api_name = "get_lawfirm_log"
    api_input = get_api_input(api_name, value)
    print(API(api_name, api_input))
    '''

    '''
    api_name = "get_address_code"
    api_input = get_api_input(api_name, "江苏省", "连云港市", "高新开发区")
    print(API(api_name, api_input))
    '''

    ''' 有问题，查询为空！
        api_input = {
        "query_conds": {
            "省份": "浙江省",
            "城市": "丽水市",
            "区县": "宁畲族自治县"
        },
        "need_fields": ["省份", "城市", "区县", "城市区划代码", "区县区划代码"]
    }
    print(API("get_address_code", api_input))
    '''

    '''
    value = "山东航空股份有限公司"
    api_name = "get_company_info"
    api_input = get_api_input(api_name, value)
    print(API(api_name, api_input))
    '''



    '''
        api_input = {
        'query_conds': {
            '律师事务所名称': '河南良承律师事务所'
        },
        'need_fields': ['律师事务所名称', '律师事务所唯一编码', '律师事务所负责人', '事务所注册资本', '事务所成立日期', '律师事务所地址', '通讯电话', '通讯邮箱', '律所登记机关']
    }
    '''

    '''
    api_input = {
	'query_conds': {
		'律师事务所名称': '河南良承律师事务所'
	},
	'need_fields': ['律师事务所名称', '律师事务所唯一编码', '律师事务所负责人', '事务所注册资本', '事务所成立日期', '律师事务所地址', '通讯电话', '通讯邮箱', '律所登记机关']
    }
    print(API("get_lawfirm_info", api_input))
    '''

#    api_input = {'need_fields': ['文件名', '案号', '文本摘要'], 'query_conds': {'案号': '(2019)兵08财保8号'}}
#    print(API("get_legal_abstract", api_input))

#    api_input2 = {'need_fields': ['法院名称', '法院负责人', '成立日期', '法院地址', '法院联系电话', '法院官网'], 'query_conds': {'法院名称': '福建省漳州市中级人民法院'}}
#    print(API("get_court_info", api_input2))

#    api_input3 = {'need_fields': ['地址', '省份', '城市', '区县'], 'query_conds': {'地址': '合肥市高新区科学大道91号'}}
    # api_input3 = {'need_fields': ['地址', '省份', '城市', '区县'], 'query_conds': {'地址': '保定市天威西路2222号'}}
#    print(API("get_address_info", api_input3))
    value = "上汽通用五菱汽车股份有限公司"
    api_name = "get_legal_document_list"
    api_input = get_api_input(api_name, value)

    response = API(api_name, api_input)
    print(response)

